//
//  suggestViewController.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/24.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "suggestViewController.h"

 #import "QuartzCore/QuartzCore.h"
@interface suggestViewController ()<UITextFieldDelegate,UITextViewDelegate>
@property(nonatomic,strong)UITextView *textView;
@property(nonatomic,strong)UITextField *firstText;
@property(nonatomic,strong)UITextField *telephone;
@property(nonatomic,strong)UITextField *mail;
@property(nonatomic,strong)UITextField*other;

@property(nonatomic,strong)UILabel *placeholderLabel;
@end

@implementation suggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    self.navigationItem.title = @"建议反馈";
    
    //建议
//    self.firstText = [[UITextField alloc]initWithFrame:CGRectMake(kScreenIp6(10), kScreenIp6(70), kScreenWidth - 20, kScreenIp6(100))];
//    self.firstText.placeholder = @"请输入您的建议和反馈,不少于10个字";
//   
//    self.firstText.delegate = self;
//    
//    self.firstText.textColor = [UIColor blackColor];
//    self.firstText.backgroundColor = [UIColor yellowColor];
//   
//    self.firstText.borderStyle = UITextBorderStyleRoundedRect;
// 
//    self.firstText.font = [UIFont systemFontOfSize:14];
//    [self.view addSubview:_firstText];
//
    
    self.textView = [[UITextView alloc] init];
    self.textView.font = [UIFont systemFontOfSize:14];
    self.textView.frame =CGRectMake(kScreenIp6(10), kScreenIp6(70), kScreenWidth - 20,  kScreenIp6(100));
    [self.textView.layer setCornerRadius:5];
//    self.textView.textAlignment = NSTextAlignmentLeft;
    //self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    self.textView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.textView];
    
    
    self.textView.hidden = NO;
    self.textView.delegate = self;
    //其次在UITextView上面覆盖个UILable,UILable设置为全局变量。
    self.placeholderLabel = [[UILabel alloc]init];
     self.placeholderLabel.frame =CGRectMake(kScreenIp6(7),  kScreenIp6(-50),  kScreenWidth - 40, kScreenIp6(20));
    self.placeholderLabel.text = @"请输入您的建议和反馈,不少于10个字";
     self.placeholderLabel.enabled = NO;//lable必须设置为不可用
     self.placeholderLabel.backgroundColor = [UIColor clearColor];
    [self.textView addSubview:_placeholderLabel];
    
    //电话
    self.telephone = [[UITextField alloc]initWithFrame:CGRectMake(kScreenIp6(10), kScreenIp6(180), kScreenWidth - 20, kScreenIp6(30))];
    
    self.telephone.placeholder = @"电话";
    self.telephone.textColor = [UIColor blackColor];
    self.telephone.backgroundColor = [UIColor yellowColor];
    self.telephone.delegate = self;
    self.telephone.borderStyle = UITextBorderStyleRoundedRect;
  
    self.telephone.font = [UIFont systemFontOfSize:14];
 
    [self.view addSubview:_telephone];
    

    //邮箱
    self.mail = [[UITextField alloc]initWithFrame:CGRectMake(kScreenIp6(10), kScreenIp6(230), kScreenWidth - 20, kScreenIp6(30))];
    
    self.mail.placeholder = @"邮箱";
    
    self.mail.delegate = self;
    self.mail.textColor = [UIColor blackColor];
    self.mail.backgroundColor = [UIColor yellowColor];
    self.mail.borderStyle = UITextBorderStyleRoundedRect;
    self.mail.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:_mail];
    
    
    
    //其他
    self.other= [[UITextField alloc]initWithFrame:CGRectMake(kScreenIp6(10), kScreenIp6(270), kScreenWidth - 20, kScreenIp6(30))];
    
    self.other.placeholder = @"其他联系方式,例如QQ";
    self.other.delegate = self;
    self.other.textColor = [UIColor blackColor];
   self.other.backgroundColor = [UIColor yellowColor];
    self.other.borderStyle = UITextBorderStyleRoundedRect;
    self.other.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:_other];
    
    
    
    UIButton* commitButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [commitButton setTitle:@"提交" forState:UIControlStateNormal];
    commitButton.frame = CGRectMake( kScreenIp6(160),kScreenIp6(320), kScreenIp6(50),kScreenIp6(30));
    commitButton.backgroundColor = [UIColor greenColor];
    [commitButton addTarget:self action:@selector(commitAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitButton];
    
}
    
-(void)commitAction:(UIButton*)sender
{
    
    if (self.firstText.text.length >= 10)
    {
     [MBProgressHUD showSuccess:@"谢谢您的反馈"];
     [self.navigationController popToRootViewControllerAnimated:YES];
    }

    
       
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    return  [textField resignFirstResponder];
}


-(void)textViewDidChange:(UITextView *)textView
{
    self.textView.text = textView.text;
    if (textView.text.length == 0)
    {
        self.placeholderLabel.text = @"请输入您的建议和反馈,不少于10个字";;
    }
    else
    {
         self.placeholderLabel.text = @"";
    }
    
    
   
}

//退出键盘
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([text  isEqualToString:@"\n"])
    {
        [textView  resignFirstResponder];
        return NO;
    }
    return YES;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
